home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln1286.arc
/
BNCHMARK.ADA
/
QUEENS.ADA
< prev
next >
Wrap
Text File
|
1986-10-21
|
2KB
|
88 lines
--with TEXT_IO; use TEXT_IO;
procedure ALL_QUEENS is
--
-- Eight Queens problem
-- Translated from Modula-2 by Bruce A. Bergman
-- Source available from Mark Petersen's Alpo-Net FIDO board at
-- (619) 741-3412, 300/1200/2400 8,N,1
--
-- package IIO is new INTEGER_IO(integer); use IIO;
------------------------------
-- declarations
------------------------------
a : array (1..8) of boolean;
b : array (2..16) of boolean;
c : array (integer range -7..7) of boolean;
x : array (1..8) of integer;
------------------------------
-- PRINT
------------------------------
-- procedure PRINT is
-- begin
-- for k in 1..8 loop
-- put(x(k), 4);
-- end loop;
-- new_line;
-- end PRINT;
------------------------------
-- TRY
------------------------------
procedure TRY(i : in integer) is
begin
for j in 1..8 loop
if a(j) and b(i+j) and c(i-j) then
x(i) := j;
a(j) := FALSE;
b(i+j) := FALSE;
c(i-j) := FALSE;
if i < 8 then
try(i+1);
-- else
-- print;
end if;
a(j) := TRUE;
b(i+j) := TRUE;
c(i-j) := TRUE;
end if;
end loop;
end TRY;
begin
--
-- Initialize arrays.
--
for i in 1..8 loop
a(i) := TRUE;
end loop;
for i in 2..16 loop
b(i) := TRUE;
end loop;
for i in 0..14 loop
c(i-7) := TRUE;
end loop;
--
-- Do it.
--
try(1);
end ALL_QUEENS;